package cn.edu.zbu.servlet;

import cn.edu.zbu.cn.edu.zbu.dao.CarDao;
import cn.edu.zbu.cn.edu.zbu.dao.CarDao;
import cn.edu.zbu.cn.edu.zbu.dao.CarDaoImpl;
import cn.edu.zbu.pojo.Car;
import cn.edu.zbu.pojo.Car;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "QueryIdServlet", value = "/QueryIdServlet")
public class QueryIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String idString=request.getParameter("id");
        int id=Integer.parseInt(idString);
        CarDao dao=new CarDaoImpl();
        Car car= dao.findById(id);
       request.setAttribute("car",car);
        request.getRequestDispatcher("/update.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doGet(request,response);
    }
}
